function [statistics] = image_check_result_batch(image_label_cell, ground_truth_cell, string_or_var_flag_for_gt , string_or_var_flag_for_labels, report_flag)

% This function is wrapper for the function image_check_result, and it is calculating the success and 
% failure of Image Labels function compared to the Ground Truth for several image's results.
% The function can get input cells contains strings of full path MAT files or the matrices itselfs.

% Function Inputs:
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
% image_label_cell - cell with list of I mage Label output matrices, or only their full paths.
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
% ground_truth_cell  - cell with list of GUI decipher tool Ground Truth output matrices, or only their 
% full paths.
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
% string_or_var_flag_for_gt - 
%                                                            '0' - If the ground truth cell contains the full paths.
%                                                            '1' - If the ground truth cell contains the actual matrices.
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
% string_or_var_flag_for_labels  -
%                                                            '0' - If the ground truth cell contains the full paths.
%                                                            '1' - If the ground truth cell contains the actual matrices.
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
% report_flag -  '1' if we want to print on screen a report, '0' Otherwise.
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

% Function Outputs:
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
% statistics - struct with these fields:
%                      total_score_arr(5,5) - 
%                               Each row - total labels by ground truth.
%                               Each column - total labels by image labels.
%                      total_1_gt - total_4_gt : total number of pixels that were in ground truth, for each label.
%                      tru_pct_1 - tru_pct_4 : a percent of correct labelings for each label.
%                      tru_total_pct : total percent of correct labels.
%                      total_1_vote - total_4_vote : total number of pixels that were in ground truth, for each label.
%                      tru_vote_pct_1 - tru_vote_pct_4 : a percent of correct labelings for each label.
%                      tru_total_vote_pct : total percent of correct labels.
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

statistics.total_score_arr = zeros(5,5);
total_1_gt = 0; 
total_2_gt = 0; 
total_3_gt = 0; 
total_4_gt = 0;

total_1_vote = 0; 
total_2_vote = 0; 
total_3_vote = 0; 
total_4_vote = 0;
    
if (size(image_label_cell,2)~=size(ground_truth_cell,2))
    fprintf('The lists dont match');
else        
    for i= 1:size(image_label_cell,2)
        if (string_or_var_flag_for_gt == 1)            
            ground_truth = ground_truth_cell{i};            
        else
            ground_truth = open(ground_truth_cell{i});
        end
        if (string_or_var_flag_for_labels == 1)
            image_labels = image_label_cell{i};            
        else
            image_labels = open(image_label_cell{i});
        end
        
        [image_score_struct] = image_check_result(ground_truth,image_labels, 0);
        
        statistics.total_score_arr = statistics.total_score_arr + image_score_struct.image_score_arr;
        
        total_1_gt = total_1_gt + image_score_struct.total_1;
        total_2_gt = total_2_gt + image_score_struct.total_2;
        total_3_gt = total_3_gt + image_score_struct.total_3;
        total_4_gt = total_4_gt + image_score_struct.total_4;
        
        total_1_vote = total_1_vote + image_score_struct.total_vote_1; 
        total_2_vote = total_2_vote + image_score_struct.total_vote_2; 
        total_3_vote = total_3_vote + image_score_struct.total_vote_3; 
        total_4_vote = total_4_vote + image_score_struct.total_vote_4;
            
    end %of for
    
    if ((total_1_gt>0)&&(total_1_vote>0))
        statistics.tru_pct_1 = statistics.total_score_arr(1,1)/total_1_gt;
        statistics.tru_vote_pct_1 = statistics.total_score_arr(1,1) / total_1_vote;
    else
        statistics.tru_pct_1 = 0;
        statistics.tru_vote_pct_1=0;
    end
    if ((total_2_gt>0)&&(total_2_vote>0))
        statistics.tru_pct_2 = statistics.total_score_arr(2,2)/total_2_gt;
        statistics.tru_vote_pct_2 = statistics.total_score_arr(2,2) / total_2_vote;
    else
        statistics.tru_pct_2 = 0;
        statistics.tru_vote_pct_2=0;
    end
    if((total_3_gt>0)&&(total_3_vote>0))
        statistics.tru_pct_3 = statistics.total_score_arr(3,3)/total_3_gt;
        statistics.tru_vote_pct_3 = statistics.total_score_arr(3,3) / total_3_vote;
    else
        statistics.tru_pct_3 = 0;
        statistics.tru_vote_pct_3=0;
    end
     if   ((total_4_gt>0)&&(total_4_vote>0))
         statistics.tru_pct_4 = statistics.total_score_arr(4,4)/total_4_gt;
        statistics.tru_vote_pct_4 = statistics.total_score_arr(4,4) / total_4_vote;
    else
        statistics.tru_pct_4 = 0;
        statistics.tru_vote_pct_4=0;
    end

    statistics.total_1_gt = total_1_gt;
    statistics.total_2_gt = total_2_gt;
    statistics.total_3_gt = total_3_gt;
    statistics.total_4_gt = total_4_gt;

    statistics.total_1_vote = total_1_vote;
    statistics.total_2_vote = total_2_vote;
    statistics.total_3_vote = total_3_vote;
    statistics.total_4_vote = total_4_vote;
    
    statistics.tru_total_pct = (statistics.total_score_arr(1,1)+statistics.total_score_arr(2,2)+statistics.total_score_arr(3,3)+statistics.total_score_arr(4,4))/(statistics.total_1_gt + statistics.total_2_gt + statistics.total_3_gt + statistics.total_4_gt);
    statistics.tru_total_vote_pct = (statistics.total_score_arr(1,1)+statistics.total_score_arr(2,2)+statistics.total_score_arr(3,3)+statistics.total_score_arr(4,4))/(statistics.total_1_vote + statistics.total_2_vote + statistics.total_3_vote + statistics.total_4_vote);
    
    if (report_flag==1)
        fprintf('Statistics for ');fprintf(num2str(size(image_label_cell,2)));fprintf(' images : \n');
        fprintf('************************************************************************************************************** \n');
        fprintf('Label from ground truth 1 success percent: ');fprintf(num2str(statistics.tru_pct_1));fprintf('\n');
        fprintf('Label from ground truth 2 success percent: ');fprintf(num2str(statistics.tru_pct_2));fprintf('\n');
        fprintf('Label from ground truth 3 success percent: ');fprintf(num2str(statistics.tru_pct_3));fprintf('\n');
        fprintf('Label from ground truth 4 success percent: ');fprintf(num2str(statistics.tru_pct_4));fprintf('\n');
        fprintf('Total success percentfrom ground truth: ');fprintf(num2str(statistics.tru_total_pct));fprintf('\n');    
        fprintf('Total fail percent from ground truth: ');fprintf(num2str(1-statistics.tru_total_pct));fprintf('\n');    
        fprintf('************************************************************************************************************** \n');
         fprintf('Label 1 from image labeling success percent: ');fprintf(num2str(statistics.tru_vote_pct_1));fprintf('\n');
        fprintf('Label 2 from image labeling success percent: ');fprintf(num2str(statistics.tru_vote_pct_2));fprintf('\n');
        fprintf('Label 3 from image labeling success percent: ');fprintf(num2str(statistics.tru_vote_pct_3));fprintf('\n');
        fprintf('Label 4 from image labeling success percent: ');fprintf(num2str(statistics.tru_vote_pct_4));fprintf('\n');
        fprintf('Total success percent from image labeling: ');fprintf(num2str(statistics.tru_total_vote_pct));fprintf('\n');    
        fprintf('Total fail percent from image labeling: ');fprintf(num2str(1-statistics.tru_total_vote_pct));fprintf('\n');    
        fprintf('************************************************************************************************************** \n');
    end
end %of else

